package Demo01;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class Test03 {
    public static void main(String[] args) {
        List list =new ArrayList();
        list.add("hello");
        list.add("world");
        list.add("hello");
        list.add("world");
        list.add("你好");

        //去重复
        //方法1
        System.out.println(list);//[hello, world, hello, world, 你好]
        System.out.println("================");
        HashSet hashSet = new HashSet(list);
        list.clear();//[]
        System.out.println(list);
        System.out.println("===============");
        list.addAll(hashSet);
        System.out.println(list);//[world, 你好, hello]

        System.out.println("---------------------");

        //方法2
        for (int i = 0; i <list.size()-1 ; i++) {
            for (int j = list.size()-1; j >i; j--) {
                if(list.get(j).equals(list.get(i))){
                    list.remove(j);
                }
            }
        }
        System.out.println(list);


        //方法3
//        for()
    }
}
